package org.languageguide.media;


public class QuickTimeMediaGenerator implements MediaGenerator {
	
	static final String ipJavascriptTag = "<script language=\"JavaScript\" src=\"/applets/ipqt.js\"></script>\n";
	static final String ip2JavascriptTag = "<script language=\"JavaScript\" src=\"/applets/ipqt.js\"></script>\n";
	static final String alphaJavascriptTag = "<script language=\"JavaScript\" src=\"/applets/alphaqt.js\"></script>\n";
	static final String irJavascriptTag = "<script language=\"JavaScript\" src=\"/applets/irqt.js\"></script>\n";
	static final String ir2JavascriptTag = "<script language=\"JavaScript\" src=\"/applets/ir2qt.js\"></script>\n";

	/*public static String[] generate(String language, String name, boolean premium){
		String[] media = new String[2];
		String soundFile = Code.root + language + "/" + name + ".m4a";
		media[0] = javascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, true); 
		return media;
	}*/
	
	public static String[] get(String soundFile, Config config){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.relativeRoot + soundFile;
		String[] media = new String[2];
		media[0] = ipJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}
	
	public String[] getAlpha(String soundFile, int seconds){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.relativeRoot + soundFile;
		System.out.println("soundFile" + soundFile);
		String[] media = new String[2];
		media[0] = alphaJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}
	
	public static String[] getIr(String soundFile, Config config){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.relativeRoot + soundFile;
		String[] media = new String[2];
		media[0] = irJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, true);
		return media;
	}
	
	public static String getQuickTimeControlTag(String soundFile, boolean autoStart) {
	  	//int index = soundFile.lastIndexOf(".");
	    //if (index != -1)
	      //soundFile = soundFile.substring(0, index);
		    StringBuffer sb = new StringBuffer(500);
		    //System.out.println("size qt beforehand: " + sb.length());
		    sb.append("<OBJECT classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\"\n");
	        sb.append(" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\"\n");
	        sb.append(" width=\"172\" height=\"30\"\n");
	        sb.append(" id=\"player\" >\n");
	        sb.append("<PARAM name=\"src\" value=\"");
	        sb.append(soundFile); 
	        sb.append("\"/>\n");
	        sb.append("<PARAM name=\"postdomevents\" value=\"true\" />");
	         
	        
			/*sb.append("<PARAM name=\"src\" value=\"/qt.mov\">\n");*/
	        sb.append("<PARAM name=\"autostart\" value=\"");
	        sb.append(autoStart);
	        sb.append("\">\n");
		    sb.append("<EMBED width=\"180\" height=\"30\"\n");
	        sb.append(" src=\"");
	        sb.append(soundFile);
	        sb.append( "\"\n");
			/*sb.append(" src=\"/qt.mov\"\n");*/
	        sb.append(" autostart=\"");
	        sb.append(autoStart); 
	        sb.append("\"\n");
	        sb.append(" name=\"player\" postdomevents=\"true\"\n");
	        sb.append(" enablejavascript=\"true\">\n");
	        sb.append("</EMBED>\n");
	        sb.append("</OBJECT>\n");;
	        //System.out.println("size qt: " + sb.length());
	        return sb.toString();
	  
	  }

	@Deprecated
	public String[] getIpTags(String soundFile) {
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.relativeRoot + soundFile;
		String[] media = new String[2];
		media[0] = ipJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}
	
	@Deprecated
	public String[] getIrTags(String soundFile) {
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.relativeRoot + soundFile;
		String[] media = new String[2];
		media[0] = irJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, true);
		return media;
	}
	
	public String[] getIp(String soundFile) {
		soundFile = Utility.relativeRoot + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = ipJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}
	
	public String[] getIp2(String soundFile) {
		soundFile = Utility.relativeRoot + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = ip2JavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}
	
	public String[] getIr(String soundFile) {
		soundFile = Utility.relativeRoot + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = irJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, true);
		return media;
	}
	
	public String[] getIR2(String soundFile) {
		soundFile = Utility.relativeRoot + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = ir2JavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}

	@Override
	public String getKey() {
		return "0";
	}

	@Override
	public String[] getAlpha2(String soundFile, int seconds) {
		soundFile = Utility.root + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = alphaJavascriptTag;
		media[1] = getQuickTimeControlTag(soundFile, false);
		return media;
	}

	public boolean useSvg(){
		return false;
	}
}